package com.otaku.admin.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.otaku.admin.dao.entity.Permission;
import com.otaku.admin.dao.entity.SelfUserDetails;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserMapper extends BaseMapper<SelfUserDetails> {

    @Select("select * from sys_user where id= #{id} ")
    SelfUserDetails findUserById(@Param("id") Integer id);
    // 查询用户信息
    @Select(" select * from sys_user where username = #{userName}")
    SelfUserDetails findByUsername(@Param("userName") String userName);

    // 查询用户的权限
    @Select(" select permission.* from sys_user user" + " inner join sys_user_role user_role"
            + " on user.id = user_role.user_id inner join "
            + "sys_role_permission role_permission on user_role.role_id = role_permission.role_id "
            + " inner join sys_permission permission on role_permission.perm_id = permission.id where user.username = #{userName};")
    List<Permission> findPermissionByUsername(@Param("userName") String userName);

    void insertUserDetail(@Param("userDetail") SelfUserDetails userDetails);
}
